package com.beehoo.dcportal.admin.action;

import java.util.List;

import com.beehoo.dcportal.admin.service.MessageTypeService;
import com.beehoo.dcportal.admin.service.PortletService;
import com.beehoo.dcportal.admin.service.ThemeService;
import com.beehoo.dcportal.common.Constant;
import com.beehoo.dcportal.common.base.BaseAction;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.MenuBean;
import com.beehoo.dcportal.model.PortletBean;
import com.beehoo.dcportal.model.ThemeBean;

public class PortletAction extends BaseAction {

	private static final long serialVersionUID = 3318809753176838018L;
	private PortletService portletService;
	private ThemeService themeService;
	private MessageTypeService messageTypeService;
	private List<PortletBean> resultList;
	private List<MenuBean> typeList;
	private ThemeBean themeBean;
	private String themeId;
	private String[] portlet;
	private String layout;

	public List<MenuBean> getTypeList() {
		return typeList;
	}

	public void setTypeList(List<MenuBean> typeList) {
		this.typeList = typeList;
	}

	public String getLayout() {
		return layout;
	}

	public void setLayout(String layout) {
		this.layout = layout;
	}

	public ThemeBean getThemeBean() {
		return themeBean;
	}

	public void setThemeBean(ThemeBean themeBean) {
		this.themeBean = themeBean;
	}

	public List<PortletBean> getResultList() {
		return resultList;
	}

	public void setResultList(List<PortletBean> resultList) {
		this.resultList = resultList;
	}

	public String getThemeId() {
		return themeId;
	}

	public void setThemeId(String themeId) {
		this.themeId = themeId;
	}

	public String[] getPortlet() {
		return portlet;
	}

	public void setPortlet(String[] portlet) {
		this.portlet = portlet;
	}

	public void setPortletService(PortletService portletService) {
		this.portletService = portletService;
	}

	public void setMessageTypeService(MessageTypeService messageTypeService) {
		this.messageTypeService = messageTypeService;
	}

	public void setThemeService(ThemeService themeService) {
		this.themeService = themeService;
	}

	public String init(){
		String streetId = (String) getSession().get(Constant.SESSION_STREET_ID);
		
		try {
			if(themeBean == null){
				themeBean = themeService.queryTheme(streetId, themeId);
			}
			layout = themeBean.getThLayout();
			typeList = messageTypeService.queryMessageTypeLs(streetId,"2",null,"000");
			resultList = portletService.queryPortlet(streetId, themeId);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
			return SUCCESS;
		}
		return INPUT;
	}
	
	public String change(){
		String streetId = (String) getSession().get(Constant.SESSION_STREET_ID);
		try {
			portletService.changePortlet(streetId, themeId, portlet);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
			return INPUT;
		}
		return SUCCESS;
	}
}
